{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "## 作业一（动手学）\n",
    "用所学的算法，处理并分析数据，对数据进行预测，并对结果作图。"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "9b37538b609d9f21"
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 请填写\n",
    "姓名：\n",
    "班级：\n",
    "学号："
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "400072665ff46ca2"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "!pip install scikit-learn pandas matplotlib seaborn"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "7e3bb25b1856bc0d"
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "# 导入包\n",
    "from sklearn.linear_model import LogisticRegression, Lasso, RidgeClassifier\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.metrics import accuracy_score\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.datasets import load_iris\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "# TODO 1 需要的自己添加或补充\n",
    "# 参考：credit-card-approval-notebook.ipynb, creditcardapporoval.ipynb"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-23T03:15:22.191444Z",
     "start_time": "2023-10-23T03:15:21.115919Z"
    }
   },
   "id": "132d9b7a39828653"
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "# 读取数据集\n",
    "df = pd.read_csv('cc_approvals.csv')\n",
    "# TODO 2 数据缺失值处理\n",
    "X = ...\n",
    "y = ..."
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-23T03:59:50.526049Z",
     "start_time": "2023-10-23T03:59:50.508076Z"
    }
   },
   "id": "bfebd409daa13f5d"
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "# 数据集分割\n",
    "trainX, testX, train_y, test_y = train_test_split(X, y, test_size=0.3, random_state=0)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-23T03:59:52.606587Z",
     "start_time": "2023-10-23T03:59:52.600794Z"
    }
   },
   "id": "cdcce865cf7f5ae2"
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "# TODO 3 模型建立\n",
    "model = LogisticRegression() # 可以更换多个模型\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-23T04:00:19.951124Z",
     "start_time": "2023-10-23T04:00:19.942564Z"
    }
   },
   "id": "40dac9784d0cf8bc"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# 模型训练\n",
    "model.fit(trainX, train_y)"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "8dcfd4addac51d90"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# 模型预测，得到精度\n",
    "score = model.score(testX, test_y)\n",
    "print(score)"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "68090228e3e4d4"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# TODO 4 作图，ROC曲线，PR曲线，参考 chapter3-1-2.ipynb\n"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "f591a912d62351ea"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# TODO 5 （可选）作图，分类展示图，参考 https://scikit-learn.org.cn/view/301.html\n"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "20ae96e9f0cd72a4"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
